package com.lzhsite.technology.designPattern.mediator.ComputerDemo;

public class MainBoard implements Mediator
{
    protected CPU cpu;
    private CDDriver cdDriver;
    private VideoCard videoCard;
    private SoundCard soundCard;

    public void setCdDriver(CDDriver cdDriver)
    {
        this.cdDriver = cdDriver;
    }

    public void setCpu(CPU cpu)
    {
        this.cpu = cpu;
    }

    public void setVideoCard(VideoCard videoCard)
    {
        this.videoCard = videoCard;
    }

    public void setSoundCard(SoundCard soundCard)
    {
        this.soundCard = soundCard;
    }

    public void changed(Colleague colleague)
    {
        if (colleague == cdDriver)
        {
            this.operateCDDriverReadData((CDDriver) colleague);
        } else if (colleague == cpu)
        {
            this.operateCPU((CPU) colleague);
        }
    }

    public void operateCDDriverReadData(CDDriver cdDriver)
    {
        String data = cdDriver.getData();
        this.cpu.executeData(data);
    }

    public void operateCPU(CPU cpu)
    {
        String videoData = cpu.getVideoData();
        String soundData = cpu.getSoundData();
        this.videoCard.showData(videoData);
        this.soundCard.soundData(soundData);
    }
}
